package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysDangerUnit;
import com.ruoyi.system.domain.SysPlan;
import com.ruoyi.system.entity.SysDangerPoint;
import com.ruoyi.system.mapper.SysPlanMapper;
import com.ruoyi.system.service.ISysPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysPlanServiceImpl implements ISysPlanService {

    @Autowired
    private SysPlanMapper sysPlanMapper;

    @Override
    public void create(SysPlan sysPlan) {
        sysPlan.setCreateUser(SecurityUtils.getUsername());
        sysPlanMapper.create(sysPlan);
    }

    @Override
    public List<SysPlan> list(SysPlan sysPlan) {
        return sysPlanMapper.list(sysPlan);
    }

    @Override
    public void delete(Integer id) {
        sysPlanMapper.delete(id);
    }

    @Override
    public void update(SysPlan sysPlan) {
        sysPlanMapper.update(sysPlan);
    }

    @Override
    public void deleteFile(Integer id) {
        sysPlanMapper.updateFileColumn(id);
    }

    @Override
    public String importExcel(List<SysPlan> sysPlans, boolean updateSupport, String operName) {
        if (StringUtils.isNull(sysPlans) || sysPlans.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        for (SysPlan sysPlan : sysPlans) {
            sysPlan.setCreateUser(operName);
        }
        sysPlanMapper.insertBatch(sysPlans);
        return "成功";
    }
}
